package com.mcptt.config.model;

import android.os.Parcel;
import android.os.Parcelable;

public class ServerInfo implements Parcelable
{
	public static String Default_Svr_Ip = "47.122.3.228";//"121.40.146.229";//"120.26.42.146";//"123.56.84.186";//"47.122.16.187";//
	public static final int Default_Svr_Port = 10001;

//	public static final String Default_HttpSvr_Ip = "120.26.42.146";
//	public static final int Default_HttpSvr_Port = 7060;

//	private String fileServerIp = Default_Svr_Ip;
	private String ip = Default_Svr_Ip;
	private int port = Default_Svr_Port;
	
	public static ServerInfo getDefault()
	{
		return new ServerInfo(Default_Svr_Ip,Default_Svr_Port);
	}
	public ServerInfo(String serverIp,int port)
	{
		this.ip = serverIp;
		this.port = port;
	}

	public String getIp()
	{
		return ip;
	}

	public String getHttpUrl()
	{
		return "http://" + ip + ":" + port;
	}
//	public void setFileServerIp(String fileServerIp) {
//		this.fileServerIp = fileServerIp;
//	}
//	public String getFileServerIp() {
//		return fileServerIp;
//	}

	public int getPort()
	{
		return port;
	}
	
	public String toCmsHttpUrl()
	{
		StringBuffer buffer = new StringBuffer("http://");
		buffer.append(ip).append(":");
		buffer.append(port).append("/");

		return buffer.toString();
	}

	public String toString()
	{
		StringBuffer buffer = new StringBuffer("ServerInfo:");
		buffer.append("Ip = ").append(ip).append(",");
		buffer.append("port = ").append(port).append(";");

		return buffer.toString();
	}

	public static final Parcelable.Creator<ServerInfo> CREATOR = new Parcelable.Creator<ServerInfo>() {
		public ServerInfo createFromParcel(Parcel in) {
			return new ServerInfo(in);
		}

		public ServerInfo[] newArray(int size) {
			return new ServerInfo[size];
		}
	};

	private ServerInfo(Parcel in) 
	{
		ip = getReadParcelableString(in.readString());
		port = in.readInt();
	}

	private String getWriteParcelableString(String str) {
		return (str == null) ? "null" : str;
	}
	private String getReadParcelableString(String str) {
		return str.equalsIgnoreCase("null") ? null : str;
	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		// TODO Auto-generated method stub
		dest.writeString(getWriteParcelableString(ip));
		dest.writeInt(port);
	}
}
